package com.huoyun.announcement.service;

import java.util.List;

import com.huoyun.announcement.bean.Announcement;
import com.huoyun.announcement.dao.AnnouncementDao;
import com.huoyun.announcement.service.evt.GetOpenedAnnouncementPageEvt;
import com.huoyun.announcement.service.evt.QueryAnnoucemnetPageEvt;
import com.huoyun.base.bean.Page;

public class AnnouncementServiceImpl implements AnnouncementService {

	private AnnouncementDao announcementDao;
	
	@Override
	public void saveAnnoucement(Announcement announcement) 
	{
		announcementDao.saveAnnoucement(announcement);
	}

	@Override
	public void update(Announcement announcement) 
	{
		announcementDao.update(announcement);
	}

	@Override
	public List<Announcement> queryAnnoucement(String groupName) 
	{
		return announcementDao.queryAnnoucement(groupName);
	}

	@Override
	public List<Announcement> queryAll() 
	{
		return announcementDao.queryAll();
	}

	@Override
	public void delete(long id) 
	{
		announcementDao.delete(id);
	}
	
	@Override
	public Page queryAnnoucemnetPage(QueryAnnoucemnetPageEvt queryAnnoucemnetPageEvt) 
	{
		com.huoyun.announcement.dao.evt.QueryAnnoucemnetPageEvt evt = new com.huoyun.announcement.dao.evt.QueryAnnoucemnetPageEvt();
		evt.setStartTime(queryAnnoucemnetPageEvt.getStartTime());
		evt.setEndTime(queryAnnoucemnetPageEvt.getEndTime());
		evt.setPageCount(queryAnnoucemnetPageEvt.getPageCount());
		evt.setPageNo(queryAnnoucemnetPageEvt.getPageNo());
		
	    long totleRecord = announcementDao.queryAnnoucemnetCount(evt);
		
		Page page = new Page();
		page.setPageNo(queryAnnoucemnetPageEvt.getPageNo());
		page.setPageCount(queryAnnoucemnetPageEvt.getPageCount());
		
		//设置总记录数
		page.setTotalRecord(totleRecord);
		//设置显示的记录列表
		page.setObjectList(announcementDao.queryAnnoucemnetPage(evt));
		
		
		return page;
	}

	@Override
	public Page getOpenedAnnouncementPage(
			GetOpenedAnnouncementPageEvt getOpenedAnnouncementPageEvt) {
		// TODO Auto-generated method stub
		com.huoyun.announcement.dao.evt.GetOpenedAnnouncementPageEvt evt=new com.huoyun.announcement.dao.evt.GetOpenedAnnouncementPageEvt();
		//System.out.println(getOpenedAnnouncementPageEvt.getNowTime());
		evt.setNowTime(getOpenedAnnouncementPageEvt.getNowTime());
		evt.setPageCount(getOpenedAnnouncementPageEvt.getPageCount());
		evt.setPageNo(getOpenedAnnouncementPageEvt.getPageNo());
		
		long totalRecord=announcementDao.getOpenedAnnouncementCount(evt);
		//System.out.println("totalRecord="+totalRecord);
		
		Page page=new Page();
		page.setPageNo(getOpenedAnnouncementPageEvt.getPageNo());
		page.setPageCount(getOpenedAnnouncementPageEvt.getPageCount());
		
		page.setTotalRecord(totalRecord);
		page.setObjectList(announcementDao.getOpenedAnnouncementPage(evt));
		
		return page;
	}

	@Override
	public Announcement getAnnouncementById(long annId) {
		// TODO Auto-generated method stub
		return announcementDao.getAnnouncementById(annId);
	}
	
	
	public AnnouncementDao getAnnouncementDao() {
		return announcementDao;
	}

	public void setAnnouncementDao(AnnouncementDao announcementDao) {
		this.announcementDao = announcementDao;
	}

}
